import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'


export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '主页',
      component: () => import('@/views/goods/index'),
      meta: { title: '商品管理', icon: 'el-icon-s-goods' }
    }]
  },
  {
    path: '/language',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'language',
        component: () => import('@/views/language/index'),
        meta: { title: '语言配置', icon: 'form' }
      }
    ]
  },
  {
    path: '/tree',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'displayConfig',
        component: () => import('@/views/displayConfig/index'),
        meta: { title: '展示配置', icon: 'form' }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    children: [
      {
        path: 'manage',
        name: 'UserManage',
        component: () => import('@/views/user/UserManage.vue'),
        meta: { title: '用户管理', icon: 'el-icon-user' }
      }
    ]
  },
  
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher 
}

export default router
